<?php
	Class Image_controller extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('image_model');
		}
		
		public function index(){
			$imgList = $this->image_model->displayAllImg();
			$data = array(
				'imgFiles'=>$imgList,
				'pageTitle'=>'Image Index',
				'page'=>'image_view',
				'error'=>''
			);
			$this->load->view('/template/template', $data);
		}
		public function uploadImage(){
			$params = array(
				'upload_path'=>'./imageUploads/',
				'allowed_types'=>'gif|jpg|png',
				'max_size' => '100000000',
				'max_width' => '1024',
				'max_height' => '768',
			);
			$this->load->library('upload',$params);
			$fieldName = 'image-file';
			if(!$this->upload->do_upload($fieldName)){
				$data = array(
					'pageTitle'=>'Image Index',
					'page'=>'image_view',
					'error'=>$this->upload->display_errors()
				);
				$this->load->view('/template/template', $data);
			}else{
				$data = array(
					'pageTitle'=>'Image Index',
					'page'=>'image_uploadComplete',
					'error'=>'',
					'upFile'=>$this->upload->data()
				);
				$imgList = $this->image_model->uploadThisImg($data['upFile']);
				$this->load->view('/template/template', $data);
			}
		}
	}
?>